package com.bestcem.xm.award.controller.param.requestaward;

import com.bestcem.xm.award.enums.SurveyStatusEnum;
import com.bestcem.xm.award.grpc.service.param.requestaward.RespondentParam;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.util.Optional;

/**
 * 答卷信息
 *
 * @author jie.yao <jie.yao@idiaoyan.com>
 * @version v1.0
 * @date 2021/8/19 16:37
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RespondentQuery {

    /**
     * 答卷id
     */
    @JsonProperty("survey_id")
    private String id;

    /**
     * 答题端ip
     */
    @JsonProperty("survey_ip")
    private String ip;

    /**
     * 投放id
     */
    @JsonProperty("deliver_id")
    private String deliverId;

    /**
     * 答卷唯一标识
     */
    @JsonProperty("seq")
    private Integer seq;

    /**
     * 答卷状态 {@link SurveyStatusEnum}
     */
    @JsonProperty("status")
    private Integer status;

    /**
     * 答卷来源
     */
    @JsonProperty("source")
    private Integer source;

    /**
     * 发出请求的时间戳
     */
    @JsonProperty("ts")
    private Long currentTime;

    /**
     * 答题花费时间
     */
    @JsonProperty("timecost")
    private Integer costTime;

    /**
     * 签名
     */
    @JsonProperty("sig")
    private String sig;

    /**
     * 入参转换为service层所需参数
     *
     * @return RespondentParam
     */
    public RespondentParam getRespondentParam() {
        RespondentParam param = new RespondentParam();
        BeanUtils.copyProperties(this, param);
        return param;
    }

    /**
     * 默认值
     */
    public void defaultValue() {
        this.source = Optional.ofNullable(this.source).orElse(0);
        this.currentTime = Optional.ofNullable(this.currentTime).orElse(0L);
    }
}
